//----------------------------------------------------------------------------
//  ,-.
// /_\___ ,   Ninja Framework
// '  ___\    (C) Riccardo Capra - http://riccar.do
//  //   \\
//----------------------------------------------------------------------------
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------------

#ifndef NJ_MUTEX_CONFIG_H
#	define NJ_MUTEX_CONFIG_H

#	include "NjNinjaSyncLib.h"

/// \def NJ_MUTEX_TRACKING_ENABLED
/// /brief Mutexes call order is stored into a fast circular buffer
///
/// This can help debugging concurrency issues;

/// \def NJ_MUTEX_STORE_LOCKER_ENABLED
/// /brief Stores into NjMutex::m_kThreadDebugId attribute the thread identifier of the thread that locked the mutex
///
/// The attribute is available for debugging purposes and it will contain the value returned by NjEventsSystem::GetCurrentThreadDebugId.
/// This is used to ensure (through assertion) that the mutex is not used recursively and also to ensure (through assertion) that Unlock
/// is called by the same thread that locked the mutex

/// \def NJ_MUTEX_STORE_USERS_ENABLED
/// /brief Stores how may threads are concurrently accessing to the same mutex methods
///
/// This is used to detect mutex destruction, while other threads are still accessing to it

/// \def NJ_MUTEX_DETECT_DEADLOCKS_ENABLED
/// /brief Enables deadlocks detection (through assertion).
///
/// Deadlocks can happen only if Lock or TryLock(NjEventsSystem::WAIT_FOREVER) are involved.
/// Normal TryLock` calls cannot trigger deadlock assertions as the wait will anyway expire within a certain time out. 
/// Please note that this debug feature is able to detect just deadlock arising by NjMutex usage.
// It cannot detect deadlocks caused by different threads using both NjMutex and other synchronization objects (for example NjSemaphore)

#	if defined(NJ_CONFIGURATION_DEBUG)
#		define NJ_MUTEX_TRACKING_ENABLED 1
#		define NJ_MUTEX_STORE_LOCKER_ENABLED 1
#		define NJ_MUTEX_STORE_USERS_ENABLED 1
#		define NJ_MUTEX_DETECT_DEADLOCKS_ENABLED 1
#	elif defined(NJ_CONFIGURATION_RELEASE)
#		define NJ_MUTEX_TRACKING_ENABLED 0
#		define NJ_MUTEX_STORE_LOCKER_ENABLED 1
#		define NJ_MUTEX_STORE_USERS_ENABLED 1
#		define NJ_MUTEX_DETECT_DEADLOCKS_ENABLED 1
#	elif defined(NJ_CONFIGURATION_SHIPPING)
#		define NJ_MUTEX_TRACKING_ENABLED 0
#		define NJ_MUTEX_STORE_LOCKER_ENABLED 0
#		define NJ_MUTEX_STORE_USERS_ENABLED 0
#		define NJ_MUTEX_DETECT_DEADLOCKS_ENABLED 0
#	endif

#	ifndef NJ_MUTEX_TRACKING_ENABLED
#		error "Unsupported build configuration"
#	endif // NJ_MUTEX_TRACKING_ENABLED

#	ifndef NJ_MUTEX_STORE_LOCKER_ENABLED
#		error "Unsupported build configuration"
#	endif // NJ_MUTEX_STORE_LOCKER_ENABLED

#	ifndef NJ_MUTEX_STORE_USERS_ENABLED
#		error "Unsupported build configuration"
#	endif // NJ_MUTEX_STORE_USERS_ENABLED

#	ifndef NJ_MUTEX_DETECT_DEADLOCKS_ENABLED
#		error "Unsupported build configuration"
#	endif // NJ_MUTEX_DETECT_DEADLOCKS_ENABLED

#endif // NJ_MUTEX_CONFIG_H
